package com.lkd.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lkd.common.VMSystem;
import com.lkd.entity.VendingMachineEntity;
import com.lkd.service.VendingMachineService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SupplyJob {

    @Autowired
    private VendingMachineService vendingMachineService;

    /**
     * 售货机扫描任务
     * @param param
     * @return
     */
    @XxlJob("supplyJobHandler")
    public ReturnT<String> supplyJobHandler(String param){
        //查找运行中的设备
        LambdaQueryWrapper<VendingMachineEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(VendingMachineEntity::getVmStatus, VMSystem.VM_STATUS_RUNNING);
        List<VendingMachineEntity> list = vendingMachineService.list(wrapper);
        //遍历调用补货发送逻辑
        for (VendingMachineEntity vendingMachineEntity : list) {
            vendingMachineService.sendSupplyTask(vendingMachineEntity.getInnerCode());
        }
        return ReturnT.SUCCESS;
    }
}
